using System;
using System.ComponentModel.DataAnnotations.Schema;
using UwinEducation.Shared.Enums;

namespace UwinEducation.Domain.Entities
{
    /// <summary>
    /// 教师课表实体
    /// </summary>
    [Table("teacher_schedules")]
    public class TeacherSchedule : EntityBase
    {
        /// <summary>
        /// 课表ID
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 教师ID
        /// </summary>
        public Guid TeacherId { get; set; }

        /// <summary>
        /// 课程ID
        /// </summary>
        public Guid CourseId { get; set; }

        /// <summary>
        /// 教室ID
        /// </summary>
        public Guid? ClassroomId { get; set; }

        /// <summary>
        /// 单价(元/课时)
        /// </summary>
        public decimal UnitPrice { get; set; }

        /// <summary>
        /// 人数限制0
        /// </summary.>
        public int Capacity { get; set; }

        /// <summary>
        /// 上课时间
        /// </summary>
        public DateTime StartTime { get; set; }

        /// <summary>
        /// 下课时间
        /// </summary>
        public DateTime EndTime { get; set; }

        /// <summary>
        /// 课表状态
        /// </summary>
        public ScheduleStatus Status { get; set; }

        /// <summary>
        /// 废弃原因
        /// </summary>
        public string? Reason { get; set; }

        /// <summary>
        /// 组ID
        /// </summary>
        public Guid GroupId { get; set; }

        /// <summary>
        /// 是否强校验
        /// </summary>
        public bool IsForceCheck { get; set; }

        /// <summary>
        /// 课程类型
        /// </summary>
        public CourseType CourseType { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remarks { get; set; }

        /// <summary>
        /// 关联的教师
        /// </summary>
        public virtual Teacher Teacher { get; set; }

        /// <summary>
        /// 关联的课程
        /// </summary>
        public virtual Course Course { get; set; }

        /// <summary>
        /// 关联的教室
        /// </summary>
        public virtual Classroom Classroom { get; set; }

        /// <summary>
        /// 关联课程明细列表
        /// </summary>

        public virtual List<TeacherScheduleDetails> TeacherScheduleDetails { get; set; }

        /// <summary>
        /// 创建教师课表
        /// </summary>
        public static TeacherSchedule Create(
            Guid teacherId,
            Guid courseId,
            Guid? classroomId,
            decimal unitPrice,
            int capacity,
            DateTime startTime,
            DateTime endTime,
            Guid groupId,
            bool isForceCheck,
            string remarks = null
        )
        {
            return new TeacherSchedule
            {
                Id = Guid.NewGuid(),
                TeacherId = teacherId,
                CourseId = courseId,
                ClassroomId = classroomId,
                UnitPrice = unitPrice,
                Capacity = capacity,
                StartTime = startTime,
                EndTime = endTime,
                Status = ScheduleStatus.Normal,
                GroupId = groupId,
                IsForceCheck = isForceCheck,
                Remarks = remarks ?? string.Empty,
                CreatedAt = DateTime.Now,
            };
        }
    }
}
